﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using JXT.PrimaryKey.Batman.Core.WcfService;
using JXT.PrimaryKey.Batman.WcfService.Interfaces;
using JXT.PrimaryKey.Batman.WcfService.Models.UserSystem;

namespace JXT.PrimaryKey.Batman.WcfService.Client.Wrapper
{
    internal class UserWrapperService : WrapperServiceBase, IUser
    {
        private IUser _user;

        public UserWrapperService(IUser innerUser, string authenticationId, string authenticationKey)
            : base((IClientChannel)innerUser, authenticationId, authenticationKey)
        {
            _user = innerUser;
        }

        public List<UserIdentity> GetUserIdentityList()
        {
            return WrapperFunction(() =>
            {
                return _user.GetUserIdentityList();
            }, true);
        }

        public User GetSingle(string id)
        {
            return WrapperFunction(() =>
            {
                return _user.GetSingle(id);
            }, true);
        }

        public User GetSingleByName(string name)
        {
            return WrapperFunction(() =>
            {
                return _user.GetSingleByName(name);
            }, true);
        }

        public User GetSingleByMail(string mail)
        {
            return WrapperFunction(() =>
            {
                return _user.GetSingleByMail(mail);
            }, true);
        }

        public BasicUser Register(RegisterUser user)
        {
            return WrapperFunction(() =>
            {
                return _user.Register(user);
            }, true);
        }

        public void ChangePassword(ChangedPassword password)
        {
            WrapperAction(() =>
            {
                _user.ChangePassword(password);
            }, true);
        }

        public void UpdateDetail(UserDetail detail)
        {
            WrapperAction(() =>
            {
                _user.UpdateDetail(detail);
            }, true);
        }

        public void UpdateLoginStatus(UpdatedStatus status)
        {
            WrapperAction(() =>
            {
                _user.UpdateLoginStatus(status);
            }, true);
        }

        public bool ExistsName(string name)
        {
            return WrapperFunction(() =>
            {
                return _user.ExistsName(name);
            }, true);
        }

        public bool ExistsMail(string mail)
        {
            return WrapperFunction(() =>
            {
                return _user.ExistsMail(mail);
            }, true);
        }

        public string SystemLogin(string id, string key)
        {
            return WrapperFunction(() =>
            {
                return _user.SystemLogin(id, key);
            });
        }

        public void SystemLogout(string id, string key)
        {
            WrapperAction(() =>
            {
                _user.SystemLogout(id, key);
            });
        }

        public void Logout(string token)
        {
            WrapperAction(() =>
            {
                _user.Logout(token);
            }, true);
        }

        public LoginUser CheckLoginStatus(string token)
        {
            return WrapperFunction(() =>
            {
                return _user.CheckLoginStatus(token);
            }, true);
        }

        public List<Role> GetRoleList()
        {
            return WrapperFunction(() =>
            {
                return _user.GetRoleList();
            }, true);
        }
    }
}
